﻿using BW.Mes.WinForms.BasicData;
using BW.Mes.WinForms.Process;
using BW.Mes.WinForms.Production.Order;
using BW.Mes.WinForms.Production.ProductionDate;
using BW.Mes.WinForms.WareHouse;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Windows.Forms;

namespace BW.Mes.WinForms
{
    public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private readonly HttpClient _httpClient;
        private readonly string _wareHouseApiBaseUrl = "https://localhost:7212";


        public Form1()
        {
            InitializeComponent();
            this.IsMdiContainer = true;
            //初始化httpClient
            _httpClient=new HttpClient();
            _httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        }

        
        /// <summary>
        /// 仓库管理-》仓库定义
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void warehouse_Cilcked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            bool warehouses = Circulation.ActivateExistingMdiChild(this, e.Link.Caption);
            if (!warehouses)
            {
               WareHoustForm warehouse = new WareHoustForm();
                warehouse.MdiParent = this;
                warehouse.Show();
            }
        }
        /// <summary>
        /// 仓库管理-》货架/库区
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Storage_Clicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            bool storage = Circulation.ActivateExistingMdiChild(this, e.Link.Caption);
            if (!storage)
            {
              StorageForm storageForm = new StorageForm();
                storageForm.MdiParent = this;
                storageForm.Show();
            }
        }

        private void Click_Process(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            foreach (Form childForm in this.MdiChildren)
            {
                if (childForm is ProcessDataForm)
                {
                    childForm.Activate();
                    return;
                }
            }

            ProcessDataForm basicForm = new ProcessDataForm();
            basicForm.MdiParent = this;
            basicForm.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

       






        //工单管理的点击事件
        private void Order_Clicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            bool storage = Circulation.ActivateExistingMdiChild(this, e.Link.Caption);
            if (!storage)
            {
                OrderForm order = new OrderForm();
                order.MdiParent = this;
                order.Show();
            }
        }
      


        private void Workshop_Chlicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            bool workshops = Circulation.ActivateExistingMdiChild(this, e.Link.Caption);
            if (!workshops)
            {
                WorkshopForm workshop = new WorkshopForm();
                workshop.MdiParent = this;
                workshop.Show();
            }
        }

        private void Line_Chlicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            bool lines = Circulation.ActivateExistingMdiChild(this, e.Link.Caption);
            if (!lines)
            {
                LineForm1 line = new LineForm1();
                line.MdiParent = this;
                line.Show();
            }
        }

        private void Material_Chlicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            bool materials = Circulation.ActivateExistingMdiChild(this, e.Link.Caption);
            if (!materials)
            {
                MaterialForm material = new MaterialForm();
                material.MdiParent = this;
                material.Show();
            }
        }

        private void Product_Chlicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            bool product = Circulation.ActivateExistingMdiChild(this, e.Link.Caption);
            if (!product)
            {
                ProductForm products = new ProductForm();
                products.MdiParent = this;
                products.Show();
            }
        }

        private void Bom_Chlicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            bool boms = Circulation.ActivateExistingMdiChild(this, e.Link.Caption);
            if (!boms)
            {
                BomForm bom = new BomForm();
                bom.MdiParent = this;
                bom.Show();
            }
        }

        private void Supperial_Chlicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            bool supps = Circulation.ActivateExistingMdiChild(this, e.Link.Caption);
            if (!supps)
            {
                SupplierForm supp = new SupplierForm();
                supp.MdiParent = this;
                supp.Show();
            }
        }

        private void kugl_Chlicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

            bool custs = Circulation.ActivateExistingMdiChild(this, e.Link.Caption);
            if (!custs)
            {
                CustomerForm cust = new CustomerForm();
                cust.MdiParent = this;
                cust.Show();
            }
        }
        /// <summary>
        /// 排版管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void productiondate_Click(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            foreach (Form childForm in this.MdiChildren)
            {
                if (childForm is ProductionDateForm)
                {
                    childForm.Activate();
                    return;
                }
            }

            ProductionDateForm date = new ProductionDateForm();
            date.MdiParent = this;
            date.Show();
        }
    }
}
